package com.fuhaiwei.struts.tag;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.TagSupport;

public class BasePathTag extends TagSupport {
	
	public int doStartTag() throws JspException {
		HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();
		StringBuilder sb = new StringBuilder();
		sb.append("<base href=\"");
		sb.append(request.getScheme()).append("://");
		sb.append(request.getServerName()).append(":").append(request.getServerPort());
		sb.append(request.getContextPath()).append("/");
		sb.append("\" />");
		try {
			pageContext.getOut().write(sb.toString());
		} catch (IOException e) {
			e.printStackTrace();
		}
		return EVAL_PAGE;
	}
}
